package 网络编程.综合练习.接收和反馈;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class 服务端 {
    public static void main(String[] args) throws IOException {
        //1.创建服务端的连接通道
        ServerSocket ss = new ServerSocket(10086);

        //2.建立连接
        Socket socket = ss.accept();

        //3.从连接通道获取输入流
        InputStreamReader isr = new InputStreamReader(socket.getInputStream());
        int b;
        while ((b = isr.read()) != -1) {
            System.out.println((char) b);
        }

        //4.回复消息
        String str = "我已经收到消息了";
        OutputStream os = socket.getOutputStream();
        os.write(str.getBytes());


        //释放资源
        socket.close();
        ss.close();
    }
}
